<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Input Output</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
MathJax = {
	tex: {
		inlineMath: '$', '$'], ['\\(', '\\)'
	},
	svg: {
		fontCache: 'global'
	}
};
</script>
<script type="text/javascript" id="MathJax-script" async
	src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Input Output' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">Architecture16Kit</a></li><li><b>Input Output</b></li></ul></div>
<p class="purpose">Input Output  Access to the keyboard and to textual windows.</p>

<ul class="toc"><li><a href="inot.html#SP1">&#167;1. Transcript support</a></li><li><a href="inot.html#SP2">&#167;2. Dictionary Parameters</a></li><li><a href="inot.html#SP3">&#167;3. Extracting Verb Numbers</a></li><li><a href="inot.html#SP4">&#167;4. Variables and Arrays</a></li><li><a href="inot.html#SP5">&#167;5. Dictionary words</a></li><li><a href="inot.html#SP6">&#167;6. Keyboard Input</a></li><li><a href="inot.html#SP7">&#167;7. Buffer Functions</a></li><li><a href="inot.html#SP8">&#167;8. Dictionary Functions</a></li><li><a href="inot.html#SP9">&#167;9. Command Tables</a></li><li><a href="inot.html#SP10">&#167;10. Action functions</a></li><li><a href="inot.html#SP11">&#167;11. The Screen</a></li><li><a href="inot.html#SP12">&#167;12. Window Colours</a></li><li><a href="inot.html#SP13">&#167;13. Main Window</a></li><li><a href="inot.html#SP14">&#167;14. Status Line</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Transcript support.</b>This is a mode in which the transcript of text in the main window is being
written out to an external file.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_TranscriptIsOn</span></span> tests whether this mode is on. <span class="extract"><span class="extract-syntax">VM_TranscriptOn</span></span> should
be called only if it is off, and tries to turn it on, returning <span class="extract"><span class="extract-syntax">true</span></span> or <span class="extract"><span class="extract-syntax">false</span></span>
according to whether or not it succeeds. <span class="extract"><span class="extract-syntax">VM_TranscriptOff</span></span> should be called
only if scripting is on.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_TranscriptIsOn</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">HDR_GAMEFLAGS</span><span class="plain-syntax">--&gt;0) &amp; </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_TranscriptOn</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">output_stream</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">VM_TranscriptIsOn</span><span class="plain-syntax">();</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_TranscriptOff</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">output_stream</span><span class="plain-syntax"> -2;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">VM_TranscriptIsOn</span><span class="plain-syntax">()) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Dictionary Parameters.</b>Each word in the dictionary data structure has two metadata fields, known
for traditional Inform 6 reasons as "dictionary parameters 1 and 2". Number 1
is a bitmap: some of the higher bits are written by the I6 compiler only when
certain compile options are set, but they will be for the code which I7
generates. Bit 6 is currently never written by I6; bit 5, marking singular
nouns, is never used by this parser.
</p>

<p class="commentary">(For speed reasons, reading of <span class="extract"><span class="extract-syntax">DICTPAR1_NOUN</span></span> and <span class="extract"><span class="extract-syntax">DICTPAR1_PREP</span></span> is done
directly by <span class="extract"><span class="extract-syntax">ParserKit</span></span> rather than by calling functions here.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> #</span><span class="identifier-syntax">dict_par1</span><span class="plain-syntax"> = </span><span class="constant-syntax">6</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> #</span><span class="identifier-syntax">dict_par2</span><span class="plain-syntax"> = </span><span class="constant-syntax">7</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_VERB</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_META</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_PLURAL</span><span class="plain-syntax"> = </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_PREP</span><span class="plain-syntax"> = </span><span class="constant-syntax">8</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_SING</span><span class="plain-syntax"> = </span><span class="constant-syntax">16</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_BIT6</span><span class="plain-syntax"> = </span><span class="constant-syntax">32</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_TRUNC</span><span class="plain-syntax"> = </span><span class="constant-syntax">64</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_NOUN</span><span class="plain-syntax"> = </span><span class="constant-syntax">128</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WordMarkedAsVerb</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">w</span><span class="plain-syntax">) &amp;&amp; ((</span><span class="identifier-syntax">w</span><span class="plain-syntax">-&gt;#</span><span class="identifier-syntax">dict_par1</span><span class="plain-syntax">) &amp; </span><span class="identifier-syntax">DICTPAR1_VERB</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WordMarkedAsMeta</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">w</span><span class="plain-syntax">) &amp;&amp; ((</span><span class="identifier-syntax">w</span><span class="plain-syntax">-&gt;#</span><span class="identifier-syntax">dict_par1</span><span class="plain-syntax">) &amp; </span><span class="identifier-syntax">DICTPAR1_META</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WorkMarkedAsUntruncatedPlural</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">w</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">b</span><span class="plain-syntax"> = </span><span class="identifier-syntax">w</span><span class="plain-syntax">-&gt;#</span><span class="identifier-syntax">dict_par1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">b</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">DICTPAR1_TRUNC</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">b</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">DICTPAR1_PLURAL</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Extracting Verb Numbers.</b>Infocom games stored verb numbers in a single byte in dictionary entries, but
they did so counting downwards, so that verb number 0 was stored as 255, 1 as
254, and so on. Inform followed suit so that debugging of Inform 1 could be
aided by using the then-available tools for dumping dictionaries from Infocom
story files; by using the Infocom format for dictionary tables, Inform's life
was easier.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DictionaryWordToVerbNum</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">$ff</span><span class="plain-syntax">-(</span><span class="identifier-syntax">w</span><span class="plain-syntax">-&gt;#</span><span class="identifier-syntax">dict_par2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Variables and Arrays.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">xcommsdir</span><span class="plain-syntax">; </span><span class="comment-syntax">true if command recording is on</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax"> = </span><span class="constant-syntax">120</span><span class="plain-syntax">; </span><span class="comment-syntax">Length of buffer array</span>

<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">buffer</span><span class="plain-syntax">    -&gt; </span><span class="constant-syntax">123</span><span class="plain-syntax">;            </span><span class="comment-syntax">Buffer for parsing main line of input</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">buffer2</span><span class="plain-syntax">   -&gt; </span><span class="constant-syntax">123</span><span class="plain-syntax">;            </span><span class="comment-syntax">Buffers for supplementary questions</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">buffer3</span><span class="plain-syntax">   -&gt; </span><span class="constant-syntax">123</span><span class="plain-syntax">;            </span><span class="comment-syntax">Buffer retaining input for "again"</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">parse</span><span class="plain-syntax">     </span><span class="identifier-syntax">buffer</span><span class="plain-syntax"> </span><span class="constant-syntax">63</span><span class="plain-syntax">;         </span><span class="comment-syntax">Parse table mirroring it</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">parse2</span><span class="plain-syntax">    </span><span class="identifier-syntax">buffer</span><span class="plain-syntax"> </span><span class="constant-syntax">63</span><span class="plain-syntax">;         </span>

<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">dict_start</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">dict_entry_size</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">dict_end</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Dictionary words.</b>This tests whether an address is probably that of a dictionary word. It's used
only for debugging output, so the false positives here (where an address is in
the dictionary table, but mid-word) really do not matter.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ProbablyDictionaryAddress</span><span class="plain-syntax"> </span><span class="identifier-syntax">addr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">UnsignedCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">HDR_DICTIONARY</span><span class="plain-syntax">--&gt;0) &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax"> &amp;&amp;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">UnsignedCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">HDR_HIGHMEMORY</span><span class="plain-syntax">--&gt;0) &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Keyboard Input.</b>The VM must provide three routines for keyboard input:
</p>

<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">VM_KeyChar()</span></span> waits for a key to be pressed and then returns the
character chosen as a ZSCII character. Function keys are mapped to unicode
characters so that Z-Machine and Glulxe key input can be handled the same.
</li><li>(b) <span class="extract"><span class="extract-syntax">VM_KeyDelay(N)</span></span> waits up to \(N/10\) seconds for a key to be pressed,
returning the ZSCII character if so, or 0 if not.
</li><li>(c) <span class="extract"><span class="extract-syntax">VM_ReadKeyboard(b, t)</span></span> reads a whole newline-terminated command
into the buffer <span class="extract"><span class="extract-syntax">b</span></span>. If the <span class="extract"><span class="extract-syntax">t</span></span> parser table is specified then it also parses it.
</li></ul>
<p class="commentary">There are elaborations to due with mouse clicks, but this isn't the place
to document all of that.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_KeyChar</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">  </span><span class="identifier-syntax">key</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">) @</span><span class="identifier-syntax">set_window</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">read_char</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">key</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">key</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="constant-syntax">8</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_DELETE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">13</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_RETURN</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">27</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_ESCAPE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">129</span><span class="plain-syntax">, </span><span class="constant-syntax">153</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_UP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">130</span><span class="plain-syntax">, </span><span class="constant-syntax">147</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_DOWN</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">131</span><span class="plain-syntax">, </span><span class="constant-syntax">149</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_LEFT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">132</span><span class="plain-syntax">, </span><span class="constant-syntax">151</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_RIGHT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">133</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">134</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">135</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F3</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">136</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F4</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">137</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F5</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">138</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F6</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">139</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F7</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">140</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F8</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">141</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F9</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">142</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F10</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">143</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F11</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">144</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_F12</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">146</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_END</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">148</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_PAGE_DOWN</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">152</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_HOME</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="constant-syntax">154</span><span class="plain-syntax">: </span><span class="identifier-syntax">key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KEY_PAGE_UP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">key</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_KeyDelay</span><span class="plain-syntax"> </span><span class="identifier-syntax">tenths</span><span class="plain-syntax">  </span><span class="identifier-syntax">key</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">read_char</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="identifier-syntax">tenths</span><span class="plain-syntax"> </span><span class="identifier-syntax">VM_KeyDelay_Interrupt</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">key</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">key</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_KeyDelay_Interrupt</span><span class="plain-syntax">; </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">; ];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ReadKeyboard</span><span class="plain-syntax"> </span><span class="identifier-syntax">a_buffer</span><span class="plain-syntax"> </span><span class="identifier-syntax">a_table</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">read</span><span class="plain-syntax"> </span><span class="identifier-syntax">a_buffer</span><span class="plain-syntax"> </span><span class="identifier-syntax">a_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> ( </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax"> : </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> &lt;= (</span><span class="identifier-syntax">a_buffer</span><span class="plain-syntax">-&gt;1) + </span><span class="constant-syntax">1</span><span class="plain-syntax"> : </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++ )</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">a_buffer</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">32</span><span class="plain-syntax">) || ((</span><span class="identifier-syntax">a_buffer</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax">) == </span><span class="constant-syntax">160</span><span class="plain-syntax">)) </span><span class="identifier-syntax">a_buffer</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="constant-syntax">32</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. Buffer Functions.</b>A "buffer", in this sense, is an array containing a stream of characters
typed from the keyboard; a "parse buffer" is an array which resolves this
into individual words, pointing to the relevant entries in the dictionary
structure. Because each VM has its own format for each of these arrays (not
to mention the dictionary), we have to provide some standard operations
needed by the rest of the template as routines for each VM.
</p>

<p class="commentary">The Z-machine buffer and parse buffer formats are documented in the DM4.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_CopyBuffer(to, from)</span></span> copies one buffer into another.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_PrintBuffer(buf)</span></span> prints a buffer.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_PrintToBuffer(buf, len, a, b, c)</span></span> prints something into a buffer.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_Tokenise(buff, parse_buff)</span></span> takes the text in the buffer <span class="extract"><span class="extract-syntax">buff</span></span> and
produces the corresponding data in the parse buffer <span class="extract"><span class="extract-syntax">parse_buff</span></span> &mdash; this is
called tokenisation since the characters are divided into words: in traditional
computing jargon, such clumps of characters treated syntactically as units
are called tokens.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">LTI_Insert</span></span> is documented in the DM4 and the <span class="extract"><span class="extract-syntax">LTI</span></span> prefix stands for
"Language To Informese": it's used only by translations into non-English
languages of play.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_CopyBuffer</span><span class="plain-syntax"> </span><span class="identifier-syntax">bto</span><span class="plain-syntax"> </span><span class="identifier-syntax">bfrom</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">bto</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">bfrom</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_PrintBuffer</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax">  </span><span class="identifier-syntax">len</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">len</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0) + </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">len</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">char</span><span class="plain-syntax">) </span><span class="identifier-syntax">buf</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_PrintToBuffer</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">output_stream</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">a</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">String</span><span class="plain-syntax">: </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">a</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Routine</span><span class="plain-syntax">: </span><span class="identifier-syntax">a</span><span class="plain-syntax">(</span><span class="identifier-syntax">b</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Object</span><span class="plain-syntax">, </span><span class="identifier-syntax">Class</span><span class="plain-syntax">: </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">b</span><span class="plain-syntax">) </span><span class="identifier-syntax">PrintOrRun</span><span class="plain-syntax">(</span><span class="identifier-syntax">a</span><span class="plain-syntax">, </span><span class="identifier-syntax">b</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">); </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">name</span><span class="plain-syntax">) </span><span class="identifier-syntax">a</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">output_stream</span><span class="plain-syntax"> -3;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0 &gt; </span><span class="identifier-syntax">len</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"Error: Overflow in VM_PrintToBuffer.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_Tokenise</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax"> </span><span class="identifier-syntax">p</span><span class="plain-syntax">; </span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;(2 + </span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;1) = </span><span class="constant-syntax">0</span><span class="plain-syntax">; @</span><span class="identifier-syntax">tokenise</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax"> </span><span class="identifier-syntax">p</span><span class="plain-syntax">; ];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">LTI_Insert</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">ch</span><span class="plain-syntax">  </span><span class="identifier-syntax">b</span><span class="plain-syntax"> </span><span class="identifier-syntax">y</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Protect us from strict mode, as this isn't an array in quite the</span>
<span class="plain-syntax">    </span><span class="comment-syntax">sense it expects</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">b</span><span class="plain-syntax"> = </span><span class="identifier-syntax">buffer</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Insert character ch into buffer at point i.</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Being careful not to let the buffer possibly overflow:</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">y</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;0) </span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;0;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Move the subsequent text along one character:</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">y</span><span class="plain-syntax">=</span><span class="identifier-syntax">y</span><span class="plain-syntax">+2 : </span><span class="identifier-syntax">y</span><span class="plain-syntax">&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> : </span><span class="identifier-syntax">y</span><span class="plain-syntax">--) </span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">y</span><span class="plain-syntax">-1);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ch</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">And the text is now one character longer:</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;1 &lt; </span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;0) (</span><span class="identifier-syntax">b</span><span class="plain-syntax">-&gt;1)++;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. Dictionary Functions.</b>Again, the dictionary structure is differently arranged on the different VMs.
This is a data structure containing, in compressed form, the text of all the
words to be recognised by tokenisation (above). In I6 for Z, a dictionary word
value is represented at run-time by its record number in the dictionary,
0, 1, 2, ..., in alphabetical order.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_InvalidDictionaryAddress(A)</span></span> tests whether <span class="extract"><span class="extract-syntax">A</span></span> is a valid record address
in the dictionary data structure.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_DictionaryAddressToNumber(A)</span></span> and <span class="extract"><span class="extract-syntax">VM_NumberToDictionaryAddress(N)</span></span>
convert between record numbers and dictionary addresses.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_InvalidDictionaryAddress</span><span class="plain-syntax"> </span><span class="identifier-syntax">addr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">UnsignedCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">dict_start</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">UnsignedCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">dict_end</span><span class="plain-syntax">) &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        ((</span><span class="identifier-syntax">addr</span><span class="plain-syntax"> - </span><span class="identifier-syntax">dict_start</span><span class="plain-syntax">) % </span><span class="identifier-syntax">dict_entry_size</span><span class="plain-syntax"> ~= </span><span class="constant-syntax">0</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_DictionaryAddressToNumber</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">w</span><span class="plain-syntax">-(</span><span class="identifier-syntax">HDR_DICTIONARY</span><span class="plain-syntax">--&gt;0 + </span><span class="constant-syntax">7</span><span class="plain-syntax">))/</span><span class="identifier-syntax">DICT_ENTRY_BYTES</span><span class="plain-syntax">; ];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_NumberToDictionaryAddress</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">HDR_DICTIONARY</span><span class="plain-syntax">--&gt;0 + </span><span class="constant-syntax">7</span><span class="plain-syntax"> + </span><span class="identifier-syntax">DICT_ENTRY_BYTES</span><span class="plain-syntax">*</span><span class="identifier-syntax">n</span><span class="plain-syntax">; ];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. Command Tables.</b>The VM is also generated containing a data structure for the grammar
produced by I6's <span class="extract"><span class="extract-syntax">Verb</span></span> and <span class="extract"><span class="extract-syntax">Extend</span></span> directives: this is essentially a
list of command verbs such as DROP or PUSH, together with a list of
synonyms, and then the grammar for the subsequent commands to be
recognised by the parser.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_CommandTableAddress</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">HDR_STATICMEMORY</span><span class="plain-syntax">--&gt;0)--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_PrintCommandWords</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">da</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">da</span><span class="plain-syntax"> = </span><span class="identifier-syntax">HDR_DICTIONARY</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0 : </span><span class="identifier-syntax">j</span><span class="plain-syntax">&lt;(</span><span class="identifier-syntax">da</span><span class="plain-syntax">+5)--&gt;0 : </span><span class="identifier-syntax">j</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">da</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">j</span><span class="plain-syntax">*</span><span class="identifier-syntax">DICT_ENTRY_BYTES</span><span class="plain-syntax"> + </span><span class="constant-syntax">14</span><span class="plain-syntax">) == </span><span class="constant-syntax">$ff</span><span class="plain-syntax">-</span><span class="identifier-syntax">i</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"'"</span><span class="plain-syntax">, (</span><span class="identifier-syntax">address</span><span class="plain-syntax">) </span><span class="identifier-syntax">VM_NumberToDictionaryAddress</span><span class="plain-syntax">(</span><span class="identifier-syntax">j</span><span class="plain-syntax">), </span><span class="string-syntax">"' "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. Action functions.</b>This looks up the address of a function like <span class="extract"><span class="extract-syntax">TakeSub</span></span> from the table of
"action subroutines".
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ActionFunction</span><span class="plain-syntax"> </span><span class="identifier-syntax">act</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> #</span><span class="identifier-syntax">actions_table</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">act</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. The Screen.</b>Our generic screen model is that the screen is made up of windows: we tend
to refer only to two of these, the main window and the status line, but
others may also exist from time to time. Windows have unique ID numbers:
the special window ID \(-1\) means "all windows" or "the entire screen",
which usually amounts to the same thing.
</p>

<p class="commentary">Screen height and width are measured in characters, with respect to the
fixed-pitch font used for the status line. The main window normally contains
variable-pitch text which may even have been kerned, and character dimensions
make little sense there.
</p>

<p class="commentary">Clearing all windows (<span class="extract"><span class="extract-syntax">WIN_ALL</span></span> here) has the side-effect of collapsing the
status line, so we need to ensure that <span class="extract"><span class="extract-syntax">statuswin_cursize</span></span> is reduced to 0,
in order to keep it accurate.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ClearScreen</span><span class="plain-syntax"> </span><span class="identifier-syntax">window</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">window</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WIN_ALL</span><span class="plain-syntax">:    @</span><span class="identifier-syntax">erase_window</span><span class="plain-syntax"> -1; </span><span class="identifier-syntax">statuswin_cursize</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WIN_STATUS</span><span class="plain-syntax">: @</span><span class="identifier-syntax">erase_window</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WIN_MAIN</span><span class="plain-syntax">:   @</span><span class="identifier-syntax">erase_window</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ScreenWidth</span><span class="plain-syntax">  </span><span class="identifier-syntax">width</span><span class="plain-syntax"> </span><span class="identifier-syntax">charw</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">HDR_SCREENWCHARS</span><span class="plain-syntax">-&gt;0); ];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ScreenHeight</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">HDR_SCREENHLINES</span><span class="plain-syntax">-&gt;0); ];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. Window Colours.</b>We can now change foreground and background colours in both Z-Machine and Glulx
(through a widely implement extension.) Inform does not keep track of which
colours have been set.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_SetWindowColours</span><span class="plain-syntax"> </span><span class="identifier-syntax">fg</span><span class="plain-syntax"> </span><span class="identifier-syntax">bg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">set_colour</span><span class="plain-syntax"> </span><span class="identifier-syntax">fg</span><span class="plain-syntax"> </span><span class="identifier-syntax">bg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_SetReverseMode</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        @</span><span class="identifier-syntax">set_text_style</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        @</span><span class="identifier-syntax">set_text_style</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. Main Window.</b>The part of the screen on which commands and responses are printed, which
ordinarily occupies almost all of the screen area.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_MainWindow()</span></span> switches printing back from another window, usually the
status line, to the main window. Note that the Z-machine implementation
emulates the Glulx model of window rather than text colours.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_MainWindow</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">statuswin_current</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">style</span><span class="plain-syntax"> </span><span class="identifier-syntax">roman</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        @</span><span class="identifier-syntax">set_window</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">statuswin_current</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. Status Line.</b>Despite the name, the status line need not be a single line at the top of
the screen: that's only the conventional default arrangement. It can expand
to become the equivalent of an old-fashioned VT220 terminal, with menus
and grids and mazes displayed lovingly in character graphics, or it can
close up to invisibility.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_StatusLineHeight(n)</span></span> sets the status line to have a height of <span class="extract"><span class="extract-syntax">n</span></span> lines
of type. (The width of the status line is always the width of the whole
screen, and the position is always at the top, so the height is the only
controllable aspect.) The \(n=0\) case makes the status line disappear.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_MoveCursorInStatusLine(line, column)</span></span> switches printing to the status line,
positioning the "cursor" &mdash; the position at which printing will begin &mdash;
at the given character grid position \((line, column)\). Line 1 represents the top
line; line 2 is underneath, and so on; columns are similarly numbered from
1 at the left.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_MoveCursorInStatusLine</span><span class="plain-syntax"> </span><span class="identifier-syntax">line</span><span class="plain-syntax"> </span><span class="identifier-syntax">column</span><span class="plain-syntax">; </span><span class="comment-syntax">1-based position on text grid</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (~~</span><span class="identifier-syntax">statuswin_current</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">         @</span><span class="identifier-syntax">set_window</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">         </span><span class="reserved-syntax">style</span><span class="plain-syntax"> </span><span class="identifier-syntax">reverse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">line</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">line</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">column</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">set_cursor</span><span class="plain-syntax"> </span><span class="identifier-syntax">line</span><span class="plain-syntax"> </span><span class="identifier-syntax">column</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">statuswin_current</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_StatusLineHeight</span><span class="plain-syntax"> </span><span class="identifier-syntax">height</span><span class="plain-syntax">  </span><span class="identifier-syntax">wx</span><span class="plain-syntax"> </span><span class="identifier-syntax">wy</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax"> </span><span class="identifier-syntax">y</span><span class="plain-syntax"> </span><span class="identifier-syntax">charh</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">statuswin_cursize</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">height</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        @</span><span class="identifier-syntax">split_window</span><span class="plain-syntax"> </span><span class="identifier-syntax">height</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">statuswin_cursize</span><span class="plain-syntax"> = </span><span class="identifier-syntax">height</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="chrst.html">&#10094;</a></li><li class="progresssection"><a href="cpblt.html">cpblt</a></li><li class="progresssection"><a href="strtp.html">strtp</a></li><li class="progresssection"><a href="stt.html">stt</a></li><li class="progresssection"><a href="mthmt.html">mthmt</a></li><li class="progresssection"><a href="chrst.html">chrst</a></li><li class="progresscurrent">inot</li><li class="progresssection"><a href="fio.html">fio</a></li><li class="progresssection"><a href="vnr.html">vnr</a></li><li class="progressnext"><a href="fio.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

